package com.TCP;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName SocketDemo
 * @Description TCP点对点
 * @Author 2214361854
 * @Date 2022/3/3 22:37
 * @Version 1.0
 */
public class SocketDemo {
//    public static void main(String[] args) throws Exception {
//        System.out.println("====服务端启动====");
//        //服务端，创建ServerSocket
//        final ServerSocket serverSocket = new ServerSocket(7777);
//        //接收连接请求
//        final Socket socket = serverSocket.accept();
//        //获取并包装缓冲字符流
//        final BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//        //读取消息
//        String msg;
//        if ((msg = br.readLine()) != null) {
//            System.out.println(socket.getRemoteSocketAddress()+"说了："+msg);
//        }
////        关闭
////        serverSocket.close();
//    }
//}
//
///**
// * 客户端
// */
//class ClientDemo{
//    public static void main(String[] args) throws Exception {
//        System.out.println("====客户端启动====");
//        //客户端，创建Soket
//        final Socket sk = new Socket("127.0.0.1",7777);
//        //获取并包装成字节打印流
//        final PrintStream ps = new PrintStream(sk.getOutputStream());
//        //发送消息并刷新流
//        ps.println("TCP信息");
//        ps.flush();
////        关闭
//        sk.close();
//    }
}